SWEP.Category			= "Nautical's Doo-Dads"

/*
hi peoples, it's nautical
if you wanna use any of the swep code, i'm at
71.205.49.140
please ask :]
*/

------------General Swep Info---------------
SWEP.Author   = "Nautical"
SWEP.Contact        = ""
SWEP.Purpose        = ""
SWEP.Instructions   = "Step one - throw moniter out the window. Step two - Repeat step one till you can't read this anymore."
SWEP.Spawnable      = False
SWEP.AdminSpawnable  = true
-----------------------------------------------

------------Models---------------------------
SWEP.ViewModel      = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl" 
-----------------------------------------------

-------------Primary Fire Attributes----------------------------------------
SWEP.Primary.Delay			= 0.9 	
SWEP.Primary.Recoil			= 0.5	
SWEP.Primary.Damage			= 100	
SWEP.Primary.NumShots		= 1		
SWEP.Primary.Cone			= 0 	
SWEP.Primary.ClipSize		= 1	
SWEP.Primary.DefaultClip	= -1	
SWEP.Primary.Automatic   	= false
SWEP.Primary.Ammo         	= "none"	
-------------End Primary Fire Attributes------------------------------------
 
-------------Secondary Fire Attributes-------------------------------------
SWEP.Secondary.Delay		= 0.9
SWEP.Secondary.Recoil		= 0
SWEP.Secondary.Damage		= 100
SWEP.Secondary.NumShots		= 1
SWEP.Secondary.Cone			= 0
SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic   	= false
SWEP.Secondary.Ammo         = "none"
trent = {}
thetrent = nil
SWEP.MoveDistance			= 2000
-------------End Secondary Fire Attributes--------------------------------

function SWEP:Initialize()
//initialize THIS physics!!!
end

function SWEP:PrimaryAttack()
//onoes entities in our tables, stealin our datas
if #trent >= 3 then return end //lulls i guess it was; added cap to prevent lag/epic crash
	local trace = self.Owner:GetEyeTrace()
	if (trace.Entity:GetClass() == "prop_physics") or (trace.Entity:GetClass() == "prop_ragdoll") then
		local ent = trace.Entity
		table.insert(trent,ent)
	end
end

function SWEP:SecondaryAttack()
// dunno what else to do :o
end

function SWEP:GetClosest( Table, mmm )
//mmmmmmm i just ate a burger.
	local Closest = 9000000
	local Ent = nil
	local Pos = mmm:GetPos()
	if( Table ) then
		for k, v in pairs(Table) do
			if( v:GetPos():Distance( Pos ) < self.MoveDistance ) then
				if( v:GetPos():Distance( Pos ) < Closest ) then
					if /*(*/((( v:IsPlayer() and v:Alive()) /*and v:GetMoveType() != 8) */ or (v:IsNPC() and v:Health() > 1)) and (v:EntIndex() != self.Owner:EntIndex())) then -- You can take it out if you only want it to target non-noclippers. I did, was kinda boring. 
						Closest = v:GetPos():Distance( Pos )
						Ent = v
					end
				end
			end
		end
	else
		return nil
	end
	if( Ent ) then
		return Ent
	else
		return nil
	end
end

function SWEP:Think() 
//screw it, it works so don't question it or the fabric of space might fall apart.
	if (trent != nil) && (#trent > 0) then
		local phys
		local xvar
		local it 
		for k,v in pairs( trent ) do
			if ValidEntity(v) then
				phys = v:GetPhysicsObject()
				if phys:IsValid() then
					xvar = 100 - v:GetPos().z
					phys:ApplyForceCenter( Vector(0,0,xvar*phys:GetMass()))
					timer.Simple(5, function() 
					if v == nil or self.Owner == nil then return end // all these checks to prevent crazy never-ending time errors XD 
						if self:GetClosest(ents.FindInSphere(v:GetPos(), self.MoveDistance), v) == nil then return end
						it = self:GetClosest(ents.FindInSphere(v:GetPos(), self.MoveDistance), v)
						if it != nil and it != NULL then
							local angle = (it:GetPos() - v:GetPos()):Angle()
							phys:EnableMotion(true)
							phys:ApplyForceOffset(angle:Forward() * 9000 + Vector(0,1000,0),angle:Forward() * 9000 + Vector(0,1000,0))		
							table.remove( trent,k )
						else 
							table.remove( trent,k )
						end
					end)
				end
			end
		end		
	end
end
function SWEP:Reload()
	for k,v in pairs(trent) do 
		table.remove(trent,k)
	end
end